<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.js"></script>
  <script>
    // 定义局部组件
    const SubTitle = {
      template:`
        <div>
          我是一个局部组件 
          {{ title }} 
        </div>
      `,
      data(){
        return {
          title:"我是局部组件数据"
        }
      }
    }
    // 定义全局组件
    const CommonHead = {
      template:`
        <div>
          <h1>我是公共的头部</h1>  
          <button @click="changeMsg">按钮</button>
          {{msg}}
          <h2>嘿嘿嘿</h2>
          <sub-title></sub-title>
        </div>
        
      `,
      data(){
        return {
          msg:'我是组件的数据'
        }
      },
      methods:{
        changeMsg(){
          this.msg = "数据改变了"
        }
      },
      components:{
        SubTitle
      }
    }
    Vue.component("CommonHead", CommonHead)
    const vm = new Vue({
      el:"#app"
    })
  </script>
</body>
</html>
